/*
 * @FilePath: /app/plc/PLCClient.h
 * @Author: Wilson
 * @Descripttion: 
 * @Date: 2021-08-19 21:37:29
 * @LastEditors: Wilson
 * @LastEditTime: 2021-08-19 23:39:51
 */
#pragma once

#include <memory>
#include <map>
#include <list>

#include "snap7.h"

namespace plc
{
    const int WRITE_BUFFER_SIZE = 8;
    const int READ_BUFFER_SIZE = 16;

    class PLCClient
    {
    public:
        bool Init(std::string ip, std::list<int> readDBList);
        void Release();

        bool WriteDB(int db, int index, int value);
        
        bool ReadDB(int db, int index);
    private:
        std::shared_ptr<TS7Client> _client;

        std::map<int, byte[WRITE_BUFFER_SIZE]> _dbWriteBuffer;
        std::map<int, byte[READ_BUFFER_SIZE]> _dbReadBuffer;

        bool sendDB(int db);
        
    };
}